package com.ms.es.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EsPageResponse<T> {

	/**
	 * 响应时间
	 */
	private String timestamp;

	/**
	 * 记录总数
	 */
	private Integer total;

	/**
	 * 总页数
	 */
	private Integer totalPage;

	/**
	 * 分页大小
	 */
	private Integer pageSize;

	/**
	 * 当前页数
	 */
	private Integer current;

	/**
	 * 当前页元素
	 */
	private List<T> records;

	public Integer getTotalPage() {
		totalPage = 1;
		if (pageSize != null) {
			if (total % pageSize == 0) {
				totalPage = total / pageSize;
			} else {
				totalPage = total / pageSize + 1;
			}
		}
		return totalPage;
	}

}
